'''
Created on Apr 29, 2010

This module contains the main screen object for IDEAvolution.

@author: dkadish
'''
from pygame import event, display, sprite, Surface
from pygame.locals import QUIT, MOUSEBUTTONDOWN
from settings import logger, WINDOW_NAME, WINDOW_SIZE, BACKGROUND_COLOUR
import sprites, graph, widgets

import pygtk
pygtk.require( "2.0" )
import gtk
from math import pi

class MainWindow:
    def gtk_main_quit( self, window, event ):
        gtk.main_quit()

#    def do_delete_event( self, window, event ):
#        # Run dialog
#        response = self.quit_dialog.run()
#        self.quit_dialog.hide()
#
#        return response != 1
#
#    def do_show_about( self, button ):
#        # Run dialog
#        self.about_dialog.run()
#        self.about_dialog.hide()
        
    def run_cairo_graphics(self, window, event):

        # Create the cairo context
        cr = window.window.cairo_create()

        # Restrict Cairo to the exposed area; avoid extra work
        cr.rectangle(event.area.x, event.area.y,
                event.area.width, event.area.height)
        cr.clip()

        self.draw(cr, *window.window.get_size())
        
    def draw(self, cr, width, height):
        cr.set_source_rgb(0.5, 0.5, 0.5)
        cr.rectangle(0, 0, width, height)
        cr.fill()

        # draw a rectangle
        cr.set_source_rgb(1.0, 1.0, 1.0)
        cr.rectangle(10, 10, width - 20, height - 20)
        cr.fill()

        # draw lines
        cr.set_source_rgb(0.0, 0.0, 0.8)
        cr.move_to(width / 3.0, height / 3.0)
        cr.rel_line_to(0, height / 6.0)
        cr.move_to(2 * width / 3.0, height / 3.0)
        cr.rel_line_to(0, height / 6.0)
        cr.stroke()

        # and a circle
        cr.set_source_rgb(1.0, 0.0, 0.0)
        radius = min(width, height)
        cr.arc(width / 2.0, height / 2.0, radius / 2.0 - 20, 0, 2 * pi)
        cr.stroke()
        cr.arc(width / 2.0, height / 2.0, radius / 3.0 - 10, pi / 3, 2 * pi / 3)
        cr.stroke()

    def __init__( self ):
        builder = gtk.Builder()
        builder.add_from_file( "../../interface/ideavolution.builder" )
        
        self.window = builder.get_object( "main_window" )
        self.layout = builder.get_object('ideas_layout')
        #self.about_dialog = builder.get_object( "aboutdialog1" )
        #self.quit_dialog  = builder.get_object( "dialog1" )

        builder.connect_signals( self )
        
        idea = widgets.Idea()
        self.layout.add(idea)
        self.layout.show_all()

if __name__=='__main__':
    win = MainWindow()
    win.window.show_all()
    gtk.main()